/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.coreGenerator.base.accessorgen;



//using TypeInfo = Inspur.Gsp.Caf.Generator.BaseInfoItem.TypeInfo;

import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.item.ClassGeneratorContext;
import com.inspur.edp.caf.generator.method.ClassMethodGenerator;
import com.inspur.edp.caf.generator.property.ClassPropertyGenerator;
import com.inspur.edp.cef.core.data.ValueObjAccessor;
import com.inspur.edp.cef.designtime.api.IGspCommonDataType;
import com.inspur.edp.cef.gencommon.MediateType;
import com.inspur.edp.cef.generator.common.MediatePropertyInfo;
import com.inspur.edp.cef.generator.coreGenerator.base.accessorgen.method.AccessorInitializeNestedGen;
import com.inspur.edp.cef.generator.coreGenerator.base.accessorgen.method.NestedAccessorAcceptChangeGen;
import com.inspur.edp.cef.generator.coreGenerator.base.accessorgen.method.NestedAccessorCtorGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.accessorgen.method.NestedAccessorInitializeGen;
import com.inspur.edp.cef.generator.coreGenerator.base.accessorgen.method.base.AccessorInitializeGen;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.BaseDataGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.DataTypeImpContext;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.EntityGeneratorContext;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.property.ChildPropGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.property.SimpleUdtDataValuePropGenerator;
import com.inspur.edp.das.commonmodel.IGspCommonObject;
import com.inspur.edp.udt.designtime.api.entity.SimpleDataTypeDef;
import java.util.ArrayList;
import org.eclipse.jdt.core.dom.Modifier;

public class NestedAcsGenerator extends BaseAcsGenerator {
    public NestedAcsGenerator(EntityGeneratorContext parContext,
         IGspCommonDataType node ,String nodeCode, MediateType targetInterfaceType) {
        super(parContext,node, nodeCode, targetInterfaceType);
    }

    public NestedAcsGenerator(EntityGeneratorContext parContext, String nodeCode, MediateType targetInterfaceType) {
        super(parContext,nodeCode, targetInterfaceType);
    }

    protected AccessorClassGenContext getAccGenContext() {
        return (AccessorClassGenContext) super.getContext();
    }


    @Override
    protected ClassGeneratorContext createClassInfoContext() {
        return new AccessorClassGenContext(ParentContext);
    }

    @Override
    protected ArrayList<Modifier.ModifierKeyword> getAccessModifier() {
        ArrayList<Modifier.ModifierKeyword> list = new ArrayList<>();
        list.add(Modifier.ModifierKeyword.PUBLIC_KEYWORD);
        return list;
    }

    @Override
    protected void addAcsExtendMethod(java.util.ArrayList<ClassMethodGenerator> methodGens) {
        super.addAcsExtendMethod(methodGens);
        ClassMethodGenerator acceptChangeGen = getAcceptChangeGenerator();
        methodGens.add(acceptChangeGen);
        methodGens.add(new AccessorInitializeNestedGen(getAccGenContext(),NodeCode, PropertyInfos,TargetInterfaceType,null,false));
//        methodGens.add(new AccessorInitializeNestedGen(getAccGenContext(), TargetInterfaceType, null, false));
    }

    @Override
    protected final TypeInfo setParentClass() {
        return new TypeInfo(ValueObjAccessor.class.getTypeName());
    }

    @Override
    protected BaseDataGenerator getChildsGenerator
            (EntityGeneratorContext parContext,
                IGspCommonObject node) {
        return null;
    }

    @Override
    protected ChildPropGenerator getChildPropGenerator(String childCode,
        MediatePropertyInfo propertyInfo, String privatePropName) {
        return null;
    }


    @Override
    public AccessorInitializeGen getInitilizeGenerator() {
        return new NestedAccessorInitializeGen();
    }
    //#endregion

    private ClassMethodGenerator getAcceptChangeGenerator() {
        return new NestedAccessorAcceptChangeGen(NodeCode, PropertyInfos, getAccGenContext());
    }

    @Override
    protected java.util.ArrayList<ClassMethodGenerator> createConstructorGenerators() {
        ArrayList<ClassMethodGenerator> list = super.createConstructorGenerators();
        if (list == null) {
            list = new java.util.ArrayList<ClassMethodGenerator>();
        }
        list.add(new NestedAccessorCtorGenerator(getName(), TargetInterfaceType));
        return list;
    }

    @Override
    protected void addExtendPropertyGenerator(java.util.ArrayList<ClassPropertyGenerator> proGenerators) {
        super.addExtendPropertyGenerator(proGenerators);
        if (Node instanceof SimpleDataTypeDef) {
            proGenerators.add(new SimpleUdtDataValuePropGenerator((SimpleDataTypeDef) Node));
        }
    }
}
